﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Ue.Extensions;

namespace Ue.Tests.Extensions
{
    /// <summary>
    /// RegexExtensions 的摘要说明
    /// </summary>
    [TestClass]
    public class RegexExtensionTests
    {
        #region Number

        [TestMethod]
        public void IsNumber()
        {
            string str = "12";

            Assert.IsTrue(str.IsInteger());
        }

        [TestMethod]
        public void NullOrEmptyIsNotNumber()
        {
            string str = "";
            Assert.IsFalse(str.IsInteger());

            str = string.Empty;
            Assert.IsFalse(str.IsInteger());

            str = null;
            Assert.IsFalse(str.IsInteger());
        }

        #endregion

        #region Letter

        [TestMethod]
        public void IsLetter()
        {
            Assert.IsTrue("a".IsLetter());
            Assert.IsTrue("aaaa".IsLetter());
            Assert.IsTrue("A".IsLetter());

            Assert.IsFalse("中".IsLetter());
            Assert.IsFalse("*".IsLetter());
            Assert.IsFalse("1".IsLetter());
        }

        #endregion

        #region IsUrlSegment

        [TestMethod]
        public void IsUrlSegment()
        {
            var url = "abcd";
            Assert.IsTrue(url.IsUrlSegment());

            url = "text.aspx";
            Assert.IsTrue(url.IsUrlSegment());

            url = "%e4%b8%ad%e5%9b%bd%e4%ba%ba";
            Assert.IsTrue(url.IsUrlSegment());

            url = "fa_fdsf";
            Assert.IsTrue(url.IsUrlSegment());

            url = "/abcd";
            Assert.IsFalse(url.IsUrlSegment());

            url = "http://www.sina.com.cn";
            Assert.IsFalse(url.IsUrlSegment());

        }

        #endregion
    }
}
